// Copyright (c) 2024-present AI-Labs

import {
    AIAudioSpeechConfig,
    AIAudioTranslationsConfig,
    AIChatConfig,
    AICommand,
    AIVideoConfig,
    AIVisionConfig,
    Image2ImageConfig,
    InpaintingConfig,
    StyleMigrationConfig,
    Text2ImageConfig
} from "@/ai/index.ts";
import { AppPlugin } from "@/plugins/AppPlugin.ts";
import { AppPluginRegistry } from "@/plugins/AppPluginRegistry.ts";

/**
 * 定义数据字典类型
 */
export type UAIEditorDict = {
    label: string,
    value: string | number,
    order?: number
}

/**
 * 定义文件上传类
 */
export type Uploader = (file: File, uploadUrl?: string, headers?: Record<string, any>, formName?: string) => Promise<Record<string, any>>;

/**
 * 定义编辑器选项配置类型
 */
export type UAIEditorOptions = {
    element: string | Element,
    content?: string,
    contentRetentionKey?: string,
    dicts?: {
        fontFamilies?: UAIEditorDict[],
        fontSizes?: UAIEditorDict[],
        lineHeights?: UAIEditorDict[],
        symbols?: UAIEditorDict[],
        emojis?: UAIEditorDict[],
    },
    header?: "ribbon" | "classic",
    theme?: "light" | "dark",
    lang?: "zh_CN" | "en_US",
    i18n?: Record<string, Record<string, string>>,
    spellCheck?: {
        enable: true | false,
        duration?: number,
        suggest?: Record<string, string>,
        exclude?: Record<string, string>,
    },
    image?: {
        uploadUrl?: string,
        uploadHeaders?: (() => Record<string, any>) | Record<string, any>,
        uploadFormName?: string,
        uploader?: Uploader,
    },
    video?: {
        uploadUrl?: string,
        uploadHeaders?: (() => Record<string, any>) | Record<string, any>,
        uploadFormName?: string,
        uploader?: Uploader,
    },
    audio?: {
        uploadUrl?: string,
        uploadHeaders?: (() => Record<string, any>) | Record<string, any>,
        uploadFormName?: string,
        uploader?: Uploader,
    },
    file?: {
        uploadUrl?: string,
        uploadHeaders?: (() => Record<string, any>) | Record<string, any>,
        uploadFormName?: string,
        uploader?: Uploader,
    },
    ai?: {
        chat?: {
            models?: Record<string, AIChatConfig>,
            commands?: AICommand[],
        },
        image?: {
            models?: {
                text2image?: Record<string, Text2ImageConfig>,
                image2image?: Record<string, Image2ImageConfig>,
                inpainting?: Record<string, InpaintingConfig>,
                stylemigration?: Record<string, StyleMigrationConfig>,
            },
            commands?: AICommand[]
        }
        audio?: {
            models?: {
                speech?: Record<string, AIAudioSpeechConfig>,
                translations?: Record<string, AIAudioTranslationsConfig>,
            },
            commands?: AICommand[]
        },
        video?: {
            models?: Record<string, AIVideoConfig>,
            commands?: AICommand[]
        },
        vision?: {
            models?: {
                image?: Record<string, AIVisionConfig>,
                video?: Record<string, AIVisionConfig>,
            },
            commands?: {
                image?: AICommand[],
                video?: AICommand[],
            }
        },
    },
    plugins?: Record<"base" | "insert" | "table" | "tools" | "page" | "export" | "ai", AppPlugin[]>,
    pluginRegistry?: AppPluginRegistry
}
